//  https://www.luogu.com.cn/problem/P1219

#include<iostream>
#include<vector>
using namespace std;

int n;
int ret = 0;
const int N = 15;
bool st1[N * 2], st2[N * 2], col[N];
vector<int> path;

void dfs(int x)
{
    if (x > n)
    {
        ret++;
        if (ret <= 3)
        {
            for (auto x : path) cout << x << " ";
            cout << endl;
        }
        return;
    }
    for (int y = 1;y <= n;y++)
    {
        if (col[y] || st1[y - x + n] || st2[y + x]) continue;
        col[y] = st1[y - x + n] = st2[y + x] = true;
        path.push_back(y);
        dfs(x + 1);
        col[y] = st1[y - x + n] = st2[y + x] = false;
        path.pop_back();
    }
}
int main()
{
    cin >> n;
    dfs(1);
    cout << ret << endl;
    return 0;
}